package com.example.micro.netty.server.httpnetty;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * 把Initializer理解成pipeline
 */
public class HttpNettyServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        //向管道加入处理器
        //得到管道
        ChannelPipeline channelPipeline = socketChannel.pipeline();

        //加入一个netty 提供的httpServerCodec（编/解码器） codec =>[coder + decoder]
        //1.HttpServerCodec 是 netty 提供的处理Http 的 编/解码器
        channelPipeline.addLast("MyHttpServerCodec", new HttpServerCodec());

        //2.增加一个自定义的handler
        channelPipeline.addLast("MyHttpNettyServerHandler", new HttpNettyServerHandler());

    }

}
